<?php
/**
 * 登录控制器
 */
Class LoginAction extends Action {

	/**
	 * 登录视图
	 */
	Public function index () {
		$this->display();
	}

	/**
	 * 处理登录操作
	 */
	Public function login () {
		if (!$this->isPost()) {
			halt('页面不存在');
		}
		if ($_SESSION['verify'] != md5($_POST['verify'])) {
			$this->error('验证码错误');
		}

		$name = $this->_post('uname');
		$pwd = $this->_post('pwd', 'md5');
		$where = array('username' => $name);
		$user = M('admin')->where($where)->find();

		if (!$user || $user['password'] != $pwd) {
			$this->error('用户名或密码错误');
		}

		if ($user['lock']) {
			$this->error('管理员被锁定');
		}
		session('username', $user['username']);
		session('uid', $user['id']);
		redirect(U('Index/index'));
	}

	/**
	 * 获取验证码
	 */
	Public function verify () {
		import('ORG.Util.Image');
		Image::buildImageVerify();
	}
}
?>